package com.itheima.spring;

import com.itheima.spring.config.HmConfig;
import com.itheima.spring.pojo.Student;
import com.itheima.spring.service.UserService;
import com.itheima.spring.test.UseAB;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Hello world!
 *
 */
public class SpringApp
{
    public static void main( String[] args )
    {
        // 基于Java-based 配置
        AnnotationConfigApplicationContext applicationContext
            = new AnnotationConfigApplicationContext(HmConfig.class);
        UserService userService = applicationContext.getBean(UserService.class);
        userService.findUserList();
        userService.findUserByUsername("admin");

        // 基于XML-based 配置
        //ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("beans.xml");
        //UserService userService = applicationContext.getBean(UserService.class);
        //userService.findUserList();

        // 关于 JDK动态代理
        //UserService userService = new UserServiceImpl();
        //UserService userServiceNew = new ServiceDynamicProxy(userService).getProxy();
        //userServiceNew.findUserList();
        //userServiceNew.findUserByUsername("admin");

        // 关于FactoryBean
        //Object obj1 = applicationContext.getBean("student");
        //Object obj2 = applicationContext.getBean("&student");
        //System.out.println(obj1);
        //System.out.println(obj2);

        // 关于替换BD信息类实现
        Object obj = applicationContext.getBean("courseService");
        System.out.println(obj);
    }
}
